package cn.xscrum.vtsp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspAdviser;
import cn.xscrum.vtsp.service.IVtspAdviserService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 志愿者顾问信息Controller
 * 
 * @author xscrum
 * @date 2021-10-01
 */
@Controller
@RequestMapping("/vtsp/adviser")
public class VtspAdviserController extends BaseController
{
    private String prefix = "vtsp/adviser";

    @Autowired
    private IVtspAdviserService vtspAdviserService;

    @RequiresPermissions("vtsp:adviser:view")
    @GetMapping()
    public String adviser()
    {
        return prefix + "/adviser";
    }

    /**
	 * 查询志愿者顾问信息列表
     */
    @RequiresPermissions("vtsp:adviser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspAdviser vtspAdviser)
    {
        startPage();
        List<VtspAdviser> list = vtspAdviserService.selectVtspAdviserList(vtspAdviser);
        return getDataTable(list);
    }

    /**
	 * 导出志愿者顾问信息列表
     */
    @RequiresPermissions("vtsp:adviser:export")
    @Log(title = "志愿者顾问信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspAdviser vtspAdviser)
    {
        List<VtspAdviser> list = vtspAdviserService.selectVtspAdviserList(vtspAdviser);
        ExcelUtil<VtspAdviser> util = new ExcelUtil<VtspAdviser>(VtspAdviser.class);
        return util.exportExcel(list, "adviser");
    }

    /**
	 * 新增志愿者顾问信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存志愿者顾问信息
     */
    @RequiresPermissions("vtsp:adviser:add")
    @Log(title = "志愿者顾问信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VtspAdviser vtspAdviser)
    {
        return toAjax(vtspAdviserService.insertVtspAdviser(vtspAdviser));
    }

    /**
	 * 修改志愿者顾问信息
     */
    @GetMapping("/edit/{adviserId}")
    public String edit(@PathVariable("adviserId") Long adviserId, ModelMap mmap)
    {
        VtspAdviser vtspAdviser = vtspAdviserService.selectVtspAdviserById(adviserId);
        mmap.put("vtspAdviser", vtspAdviser);
        return prefix + "/edit";
    }

    /**
	 * 修改保存志愿者顾问信息
     */
    @RequiresPermissions("vtsp:adviser:edit")
    @Log(title = "志愿者顾问信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspAdviser vtspAdviser)
    {
        return toAjax(vtspAdviserService.updateVtspAdviser(vtspAdviser));
    }

    /**
	 * 删除志愿者顾问信息
     */
    @RequiresPermissions("vtsp:adviser:remove")
    @Log(title = "志愿者顾问信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vtspAdviserService.deleteVtspAdviserByIds(ids));
    }
}
